<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        Quyet
 * @version         v.1.0
 * @created         18/6/2014
 * @Description :   Controller employee
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_employee extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_employee', 'em');
        $this->session->unset_userdata('cmbMonth');
        $this->session->unset_userdata('cmbYear');
    }

    /*
     * @author :        Quyet
     * @created:        18/6/2014
     * @Input :         (Interger) $page
     * @Description:    Load Employee screen
     */

    function index($page = 0) {
        $data = $this->em->getAllData($page);
        $this->load->view('layout', $data);
    }

    /*
     * @author :        Quyet
     * @created:        20/6/2014
     * @Input :         (Interger) $id
     * @Description:    update or insert data into employee
     */

    function updateEmployee() {
        $id = $this->input->post('txtEmployeeId');
        /* check exists */
        $employee = TRUE;
        if ($id) {
            $employee = $this->em->countEmployeeById($id);
        }
        if (!$employee) {
            redirect('/employee');
        }
        $temp = array();
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->em->validate();
            if ($validateFlag) {
                /* validate success */
                $temp = $this->em->updateEmployee($id);
            }
        }
        $data = $this->em->getAddEmployee($id);
        $this->load->view('layout', array_merge($data, $temp));
    }

}

?>